/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Data;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author NGOCLINH-PC
 */
public class EnrollEvent {

    public static void Cdelete(int idcate) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    int EnrollEventID;
    int EventID;
    int MemberID;
    int Ispayment;
    String DateReg;
    String DatePay;
    int PayID;
    int Status;

    public EnrollEvent() {
    }

    public EnrollEvent(int EnrollEventID, int EventID, int MemberID, int Ispayment, String DateReg, String DatePay, int PayID, int Status) {
        this.EnrollEventID = EnrollEventID;
        this.EventID = EventID;
        this.MemberID = MemberID;
        this.Ispayment = Ispayment;
        this.DateReg = DateReg;
        this.DatePay = DatePay;
        this.PayID = PayID;
        this.Status = Status;
    }

    public int getEnrollEventID() {
        return EnrollEventID;
    }

    public void setEnrollEventID(int EnrollEventID) {
        this.EnrollEventID = EnrollEventID;
    }

    public int getEventID() {
        return EventID;
    }

    public void setEventID(int EventID) {
        this.EventID = EventID;
    }

    public int getMemberID() {
        return MemberID;
    }

    public void setMemberID(int MemberID) {
        this.MemberID = MemberID;
    }

    public int getIspayment() {
        return Ispayment;
    }

    public void setIspayment(int Ispayment) {
        this.Ispayment = Ispayment;
    }

    public String getDateReg() {
        return DateReg;
    }

    public void setDateReg(String DateReg) {
        this.DateReg = DateReg;
    }

    public String getDatePay() {
        return DatePay;
    }

    public void setDatePay(String DatePay) {
        this.DatePay = DatePay;
    }

    public int getPayID() {
        return PayID;
    }

    public void setPayID(int PayID) {
        this.PayID = PayID;
    }

    public int getStatus() {
        return Status;
    }

    public void setStatus(int Status) {
        this.Status = Status;
    }

    public static void EnInser(int EventID, int MemID, int isPayMent, String dateCreate, String DatePay, int PayID, int Status) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("Insert into EnrollEvent values(?,?,?,?,?,?,?)");
            st.setInt(1, EventID);
            st.setInt(2, MemID);
            st.setInt(3, isPayMent);
            st.setString(4, dateCreate);
            st.setString(5, DatePay);
            st.setInt(6, PayID);
            st.setInt(7, Status);
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "Update Successful!");
                //response.sendRedirect("DangKi.jsp");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void Cupdate(int CateID, int isplay, String DatePay, int CateStatus) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("update EnrollEvent SET IsPayment=?,DatePay=?, Status=? WHERE EnrollEventID=?");
            st.setInt(1, isplay);
            st.setString(2, DatePay);
            st.setInt(3, CateStatus);
            st.setInt(4, CateID);
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "Update Successful!");
                //response.sendRedirect("DangKi.jsp");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public ArrayList<EnrollEvent> Sselect() {
        try {
            ArrayList<EnrollEvent> listCate = new ArrayList<EnrollEvent>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM EnrollEvent");
            while (rs.next()) {
                EnrollEvent cate = new EnrollEvent(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getString(5), rs.getString(6), rs.getInt(7), rs.getInt(8));
                listCate.add(cate);// 
            }
            return listCate;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public ArrayList<EnrollEvent> SselectByID(int id) {
        try {
            ArrayList<EnrollEvent> listCate = new ArrayList<EnrollEvent>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM EnrollEvent where EnrollEventID=" + id);
            while (rs.next()) {
                EnrollEvent cate = new EnrollEvent(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getString(5), rs.getString(6), rs.getInt(7), rs.getInt(8));
                listCate.add(cate);// 
            }
            return listCate;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    public ArrayList<EnrollEvent> SselectByMemID(int id) {
        try {
            ArrayList<EnrollEvent> listCate = new ArrayList<EnrollEvent>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM EnrollEvent where MemberID=" + id);
            while (rs.next()) {
                EnrollEvent cate = new EnrollEvent(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getString(5), rs.getString(6), rs.getInt(7), rs.getInt(8));
                listCate.add(cate);// 
            }
            return listCate;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public static void Cmtdelete(int CateID) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("DELETE FROM EnrollEvent WHERE EnrollEventID=?");
            st.setInt(1, CateID);
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "DELETE Successful!");
                //response.sendRedirect("DangKi.jsp");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
